<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            position:relative;
            width: 300px;
            height: 300px;
            background-color: pink;

        }
    </style>
</head>
<body>
<div class="box">123</div>
<script>
var box = document.querySelector(".box");
box.addEventListener("mousedown",function(e){
    var x = e.pageX - this.offsetLeft;
    var y = e.pageY - this.offsetTop;

    document.addEventListener("mousemove",move)

    function move(e){
          box.style.left = e.pageX - x + "px";
          box.style.top = e.pageY - y + "px";
    }
    document.addEventListener("mouseup",function(){
        document.removeEventListener("mousemove",move);
    })    
})
</script>
</body>
</html>